<html xmlns:th="http://www.thymeleaf.org">

<head>
    <title>教师管理</title>
    <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
    <!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
        integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> -->
    <link rel="stylesheet" href="/css/font-awesome.min.css">
    <script src="/js/jquery.min.js"></script>
    <script src="/js/popper.min.js"></script>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
    <style>
        .admin-left {
            height: 100%;
            background-color: #428bca;
            min-width: 120px !important;
        }

        .navbar {
            margin-bottom: 0;
        }

        .row {
            margin: 0 auto;
        }
    </style>
</head>

<body>
<div th:insert="template::header"></div>
<div class="container-fluid">
    <div class="row">
        <div th:insert="template::admin_left"></div>
        <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10">
            <h3>学生管理</h3>
            <hr/>
            <div style="margin-top: 10px; padding-left:5px;">
                <ol class="breadcrumb">
                    <li><a href="#">学生管理</a></li>
                    <li><a href="#" class="active" th:text="${param.classId==''?'全部班级':param.classId}"></a></li>
                </ol>
            </div>
            <div class="col-lg-2 col-sm-2 col-md-2 col-xs-2"></div>
            <div class="col-lg-8 col-sm-8 col-md-8 col-xs-8">
                <div class="admin-right">
                    <button class="btn btn-default" type="submit" id="add_stu" style="margin-top: 5px;">新增学生</button>
                    <form class="form-inline pull-right">
                        <div class="form-group">
                            <label for="exampleInputName2"></label>
                            <input type="text" class="form-control" id="exampleInputName2" placeholder="姓名">
                        </div>
                        <button type="submit" class="btn btn-default">查找</button>
                    </form>
                    <table class="table table-bordered">
                        <tr>
                            <th>学号<a href="#"><i class="fa fa-arrow-up"></i></a><a href="#"><i
                                    class="fa fa-arrow-down"></i></a></th>
                            <th>姓名</th>
                            <th>班级</th>
                            <th>提问次数<a href="#"><i class="fa fa-arrow-up"></i></a><a href="#"><i
                                    class="fa fa-arrow-down"></i></a></th>
                            <th>上次登录时间<a href="#"><i class="fa fa-arrow-up"></i></a><a href="#"><i
                                    class="fa fa-arrow-down"></i></a></th>
                            <th>操作</th>
                        </tr>
                        <tr th:each="student:${students.list}">
                            <td th:text="${student.studentId}"></td>
                            <td th:text="${student.name}"></td>
                            <td th:text="${student.classId}"></td>
                            <td th:text="${student.question}"></td>
                            <td th:text="${#dates.format(student.lastLoginTime, 'yyyy-MM-dd HH:mm')}"></td>
                            <td><a href="#">修改信息</a><a href="#"> 重置密码</a><a href="#"> 删除</a></td>
                        </tr>
                    </table>
                    <nav aria-label="Page navigation">
                        <ul class="pagination pull-right">
                            <li>
                                <a href="#" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                            <li><a href="#">1</a></li>
                            <li><a href="#">2</a></li>
                            <li><a href="#">3</a></li>
                            <li><a href="#">4</a></li>
                            <li><a href="#">5</a></li>
                            <li>
                                <a href="#" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        </ul>
                    </nav>
                </div>
            </div>
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                    aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="myModalLabel">新增</h4>
                        </div>
                        <div class="modal-body">
                            <div class="form-group">
                                <label for="stu_id">学生学号</label>
                                <input type="text" name="stu_id" class="form-control" id="stu_id" placeholder="学生学号">
                            </div>
                            <div class="form-group">
                                <label for="stu_name">学生姓名</label>
                                <input type="text" name="stu_name" class="form-control" id="stu_name"
                                       placeholder="学生姓名">
                            </div>
                            <div class="form-group">
                                <label for="stu_class">所在班级</label>
                                <input type="text" name="stu_class" class="form-control" id="stu_class"
                                       placeholder="所在班级">
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal"><span
                                    class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭
                            </button>
                            <button type="button" id="btn_submit" class="btn btn-primary" data-dismiss="modal"><span
                                    class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-2 col-sm-2 col-md-2 col-xs-2"></div>
    </div>


</div>

<script>
    $(function () {
        $(".panel-heading").click(function (e) {
            /*切换折叠指示图标*/
            $(this).find("span").toggleClass("glyphicon-chevron-down");
            $(this).find("span").toggleClass("glyphicon-chevron-up");
        });
    });
    //注册新增按钮的事件
    $("#add_stu").click(function () {
        $("#myModalLabel").text("新增");
        $('#myModal').modal();
    });

    $("#btn_submit").click(
        function () {
            const id = $("#stu_id").val();
            const name = $("#stu_name").val();
            const classId = $("#stu_class").val();
            $.ajax(
                {
                    url: "/addStudent",
                    method: "post",
                    data: {
                        "stuId": id,
                        "stuName": name,
                        "stuClassId": classId
                    },
                    success: function (data) {
                        if (data.code == 200) {
                            alert("添加学生成功!");
                        } else {
                            alert("添加学生失败!");
                        }
                    },
                    fail: function (data) {
                        alert("系统异常!");
                    }
                }
            )
        }
    )
</script>
</body>

</html>